package cn.flying.cloud.oa.leave.controller;

import javax.annotation.Resource;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.flying.cloud.base.common.vo.PageRequest;
import cn.flying.cloud.base.common.vo.PageResponse;
import cn.flying.cloud.base.common.vo.Rt;
import cn.flying.cloud.oa.leave.entity.OaLeaveApply;
import cn.flying.cloud.oa.leave.service.OaLeaveApplyService;

/**
 * 请假流程申请表 前端控制器
 *
 * @author: admin
 * @date: 2024-12-26 20:48:41
 * @version: 1.0
 */
@RestController
@RequestMapping("/oa/leave/apply")
public class OaLeaveApplyController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private OaLeaveApplyService oaLeaveApplyService;

    /**
     * 分页查询请假流程申请表数据
     *
     * @param request
     * @return
     */
    @PostMapping("page")
    public PageResponse<OaLeaveApply> page(@RequestBody PageRequest<OaLeaveApply> request) {
        return oaLeaveApplyService.getPageList(request);
    }

    /**
     * 列表查询请假流程申请表数据
     *
     * @param oaLeaveApply
     * @return
     */
    @PostMapping("list")
    public Rt list(@RequestBody OaLeaveApply oaLeaveApply) {
        List<OaLeaveApply> list = oaLeaveApplyService.getList(oaLeaveApply);
        return Rt.success(list);
    }

    /**
     * 查询请假流程申请表详情数据
     *
     * @param oaLeaveApply
     * @return
     */
    @PostMapping("detail")
    public Rt detail(OaLeaveApply oaLeaveApply) {
        return Rt.success(oaLeaveApplyService.getOneObj(oaLeaveApply));
    }

    /**
     * 根据主键ID查询请假流程申请表详情数据
     *
     * @param id 主键ID
     * @return
     */
    @PostMapping("getById")
    public Rt getById(Long id) {
        OaLeaveApply oaLeaveApply = oaLeaveApplyService.getById(id);
        return Rt.success(oaLeaveApply);
    }

    /**
     * 保存请假流程申请表数据
     *
     * @param oaLeaveApply
     * @return
     */
    @PostMapping("save")
    public Rt save(@RequestBody OaLeaveApply oaLeaveApply) {
        if (Objects.isNull(oaLeaveApply.getId())) {
            // 新增
            oaLeaveApplyService.createObj(oaLeaveApply);
        } else {
            // 更新
            oaLeaveApplyService.updateObj(oaLeaveApply);
        }
        return Rt.success("保存成功！");
    }

    /**
     * 删除请假流程申请表数据
     *
     * @param oaLeaveApply
     * @return
     */
    @PostMapping("delete")
    public Rt delete(OaLeaveApply oaLeaveApply) {
        oaLeaveApplyService.deleteObj(oaLeaveApply);
        return Rt.success("删除成功！");
    }
}
